package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.entity.TlGoods;
import com.qf.mapper.GoodsMapper;
import com.qf.service.GoodsService;
import com.qf.utils.Mycode;
import com.qf.utils.ResultMsg;
import org.jcp.xml.dsig.internal.dom.DOMXMLObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.bind.DefaultValue;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, TlGoods> implements GoodsService {

    @Autowired(required = false)
    GoodsMapper goodsMapper;

    @Override
    public ResultMsg selectOne(Integer gid) {
        TlGoods goods = super.getById(gid);
        return ResultMsg.SUCCESS(goods);
    }

    @Override
    public ResultMsg selectAll() {
        List<TlGoods> list = super.list();
        return ResultMsg.SUCCESS(list);
    }

    @Override
    public ResultMsg selectBySortIdAndOne(Integer sid) {
        QueryWrapper<TlGoods> wrapper = new QueryWrapper<>();
        wrapper.eq("sort_id",sid);
        List<TlGoods> list = super.list(wrapper);
        return ResultMsg.SUCCESS(list);
    }

    @Override
    public ResultMsg findAll(int start,int end) {
        List<TlGoods> all = goodsMapper.findAll(start,end);
        if (all!=null){
            return ResultMsg.SUCCESS(all);
        }
        return ResultMsg.ERROR(Mycode.GOODSFIND_ERRO);//商品查询失败
    }

    @Override
    public ResultMsg selectByGoodsIdAndOne(Integer gid) {
        TlGoods tlGoods = goodsMapper.selectById(gid);
        QueryWrapper<TlGoods> wrapper = new QueryWrapper<>();
        wrapper.eq("sort_id",tlGoods.getSortId());
        List<TlGoods> list = super.list(wrapper);
        return ResultMsg.SUCCESS(list);
    }

    @Override
    public ResultMsg selectLike(String src) {
        List<TlGoods> tlGoods = goodsMapper.selectLike(src);
        return ResultMsg.SUCCESS(tlGoods);
    }
}
